package com.llxy.web.controller.worker;
import com.llxy.common.annotation.Log;
import com.llxy.common.core.controller.BaseController;
import com.llxy.common.core.domain.AjaxResult;
import com.llxy.common.core.page.TableDataInfo;
import com.llxy.common.enums.BusinessType;
import com.llxy.worker.domain.School;
import com.llxy.worker.service.SchoolService;
import com.llxy.worker.service.impl.SchoolServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
* (t_school)表控制层
*
* @author 马瑞龙
*/
@RestController
@RequestMapping("/worker/school")
public class SchoolController extends BaseController {
    /**
    * 服务对象
    */
    @Autowired
    private SchoolService schoolService;

    /**
     * 获取培训学校列表
     */
    @PreAuthorize("@ss.hasPermi('worker:school:list')")
    @ApiOperation(httpMethod = "GET", value = "获取培训学校列表", notes = "获取培训学校列表")
    @GetMapping("/list")
    public TableDataInfo list(School school)
    {
        startPage();
        List<School> schoolList = schoolService.selectList(school);
        return getDataTable(schoolList);
    }

    /**
     * 获取培训学校列表 不分页
     */
    @PreAuthorize("@ss.hasPermi('worker:school:list')")
    @ApiOperation(httpMethod = "GET", value = "获取培训学校列表", notes = "获取培训学校列表")
    @GetMapping("/allList")
    public AjaxResult allList()
    {
        List<School> schoolList = schoolService.selectList(null);
        return success(schoolList);
    }


    /**
     * 根据编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('worker:school:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Integer id)
    {
        return success(schoolService.selectByPrimaryKey(id));
    }

    /**
     * 新增培训学校
     */
    @PreAuthorize("@ss.hasPermi('worker:school:add')")
    @Log(title = "新增培训学校", businessType = BusinessType.INSERT)
    @ApiOperation(httpMethod = "POST", value = "新增培训学校", notes = "新增培训学校")
    @PostMapping
    public AjaxResult add(@Validated @RequestBody School school)
    {
        school.setCreateBy(getUsername());
        return toAjax(schoolService.insertSelective(school));
    }

    /**
     * 修改培训学校
     */
    @PreAuthorize("@ss.hasPermi('worker:school:edit')")
    @Log(title = "修改培训学校", businessType = BusinessType.UPDATE)
    @ApiOperation(httpMethod = "PUT", value = "修改培训学校", notes = "修改培训学校")
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody School school)
    {
        school.setUpdateBy(getUsername());
        return toAjax(schoolService.updateByPrimaryKeySelective(school));
    }

    /**
     * 删除培训学校
     */
    @PreAuthorize("@ss.hasPermi('worker:support:remove')")
    @Log(title = "培训学校管理", businessType = BusinessType.DELETE)
    @ApiOperation(httpMethod = "DELETE", value = "删除培训学校", notes = "删除培训学校")
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Integer id)
    {
        return toAjax(schoolService.deleteByPrimaryKey(id));
    }


    
}
